package com.ch.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

//请求转发
@WebServlet(name = "ForwordServlet", value = "/ForwordServlet")
public class ForwordServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        if (request.getParameter("a")!=null){
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("/MathServlet");
            requestDispatcher.forward(request,response);
        }else if (request.getParameter("edu")!=null || request.getParameter("likes")!=null){
            RequestDispatcher requestDispatcher = request.getRequestDispatcher("/YourItemServlet");
            requestDispatcher.forward(request,response);
        }else {
            response.sendRedirect("result.html");
        }
    }
}
/**
 *    请求转发与响应重定向的区别
 *    1.请求转发是内部跳转， 响应重定向是外部跳转
 *            内部 ==> 服务器，  外部==> 服务器外部 ==> 浏览器
 *    2.      请求转发:地址栏不变,    响应重定向：改变
 *    3.      请求转发：只能跳转服务器内部资源，
 *            响应重定向： 可以跳转服务器外部资源
 *    4，     请求转发：效率高，反之...
 */